﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DB_NH
{
    using NHibernate;
    using NHibernate.Mapping.ByCode;
    using NHibernate.Mapping.ByCode.Conformist;

    /// <summary>
    /// 公共Entity，所有的都继承自该Entity
    /// </summary>
    public class Entity
    {
        /// <summary>
        /// ID
        /// </summary>
        public virtual string Id { get; set; }

        /// <summary>
        /// 是否有效
        /// </summary>
        public virtual int IsValid { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public virtual DateTime CreateDate { get; set; }

        public Entity()
        {
            this.Id = ywxt.Common.Common.NewID();
            this.CreateDate = DateTime.Now;
            this.IsValid = 1;
        }
    }

    /// <summary>
    /// 公共Entity映射
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class EntityMapping<T> : ClassMapping<T> where T : Entity
    {
        public EntityMapping()
        {
            //映射ID
            Id(x => x.Id, map =>
            {
                map.Length(40);
            });

            //映射是否有效
            Property(x => x.IsValid);

            //映射创建时间
            Property(x => x.CreateDate);
        }
    }
}
